package com.spic.business.alarm.service.impl;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.spic.business.alarm.domain.WeatherDataModel;
import com.spic.business.alarm.mapper.WeatherDataMapper;
import com.spic.business.alarm.service.WeatherDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;

/**
 * WeatherDataServiceImpl
 *
 * @author 张博
 * @version 1.0
 * @date 2021/7/8 15:39
 */
@Slf4j
@Service
public class WeatherDataServiceImpl implements WeatherDataService
{

    @Autowired
    private WeatherDataMapper weatherDataMapper;

    @Override
    public WeatherDataModel getNewestOne() {
        WeatherDataModel weatherDataModel = weatherDataMapper.getNewestOne();
        Float windRate = weatherDataModel.getWindRate();
        float[] levels =  {0.2f, 1.5f, 3.3f,5.4f,7.9f,10.7f,13.8f,17.1f,20.7f,24.4f,28.4f,32.6f,26.9f,41.4f,46.1f,50.9f,56.0f};
        int level = 0;
        for (int i = 0; i < levels.length; i++) {
            if (windRate <= levels[i]) {
                level = i;
                break;
            }
        }
        weatherDataModel.setWindRate(Float.valueOf(level));
        return weatherDataModel;
    }
}